package com.demo.study.creative.d05_singleton;

/**
 * @author Baymax
 * @since 2021/1/18
 */
public class Singleton {
    private static Singleton instance = new Singleton();

    private Singleton() {
    }

    public static Singleton instance() {
        return instance;
    }

    public void doSomething() {
        System.out.println("Singleton doSomething execute...");
    }

    public static void main(String[] args) throws InterruptedException {
        Singleton.instance().doSomething();

        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Singleton sgt1 = Singleton.instance();
                    System.out.println("current task: " + sgt1.hashCode());
                }
            }).start();
        }
        System.out.println("---------------------------------------------");
    }
}
